home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / QuickTime / JPEG Sample / Source / aevt.c next >
Encoding:
C/C++ Source or Header  |  1996-05-22  |  4.3 KB  |  176 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich & Guillermo Ortiz
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            4/3/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28.  
  29. #include <AppleEvents.h>
  30. #include <Windows.h>
  31.  
  32. #include "App.h"
  33. #include "Proto.h"
  34.  
  35.  
  36. //----------------------------------------------------------------------
  37. //
  38. //    Globals - 
  39. //
  40. //----------------------------------------------------------------------
  41.  
  42. extern Boolean        gDone;
  43.  
  44.  
  45. //----------------------------------------------------------------------
  46. //
  47. //    AEInit - initialize all the core apple events
  48. //
  49. //
  50. //----------------------------------------------------------------------
  51.  
  52. OSErr AEInit(void)
  53. {    
  54.     OSErr        err = noErr;
  55.                     
  56.                                 //    install auto Open App
  57.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  58.                                 NewAEEventHandlerProc(DoAEOpenApp), 0L, false );
  59.                                                     
  60.     if (err == noErr)            // install auto Quit App
  61.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  62.                                     NewAEEventHandlerProc(DoAEQuitApp), 0L, false );
  63.         
  64.     if (err == noErr)            // install auto Open Document
  65.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  66.                                     NewAEEventHandlerProc(DoAEOpenDoc),0L,false);
  67.                                                         
  68.     if (err == noErr)            // install auto Print Document
  69.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  70.                                     NewAEEventHandlerProc(DoAEPrintDoc),0L,false);
  71.     
  72.                             
  73.     return err;
  74.                                                 
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------
  79. //
  80. //    DoAEOpenApp - called by the Finder at launch time
  81. //
  82. //
  83. //----------------------------------------------------------------------
  84.  
  85. pascal OSErr DoAEOpenApp(AppleEvent event,AppleEvent reply,long refCon)
  86. {
  87.     #pragma unused( event, reply, refCon )
  88.  
  89.     (void)CreateWindow(128, nil, nil, nil, true,
  90.                         documentProc, kDocKind, (WindowPtr)-1, true, nil);
  91.                         
  92.     return noErr;
  93.         
  94. }
  95.  
  96.  
  97. //----------------------------------------------------------------------
  98. //
  99. //     DoAEQuitApp -    called when the Finder asks app to quit
  100. //
  101. //
  102. //----------------------------------------------------------------------
  103.  
  104. pascal OSErr DoAEQuitApp(AppleEvent event,AppleEvent reply,long refCon)
  105. {
  106.     #pragma unused( event, reply, refCon )
  107.  
  108.     // set the global quit flag
  109.     gDone = true;
  110.     
  111.     return noErr;
  112.         
  113. }
  114.  
  115.  
  116. //----------------------------------------------------------------------
  117. //
  118. //    DoAEOpenDoc - called when the Finder asks app to open a document
  119. //
  120. //
  121. //----------------------------------------------------------------------
  122.  
  123. pascal OSErr DoAEOpenDoc(AppleEvent event,AppleEvent reply,long refCon)
  124. {
  125.     #pragma unused( reply, refCon )
  126.     
  127.  
  128.     return noErr;
  129.  
  130. }
  131.                 
  132.                                         
  133. //----------------------------------------------------------------------
  134. //
  135. //    DoAEPrintDoc - called when the Finder asks app to print a document
  136. //
  137. //
  138. //----------------------------------------------------------------------
  139.  
  140. pascal OSErr DoAEPrintDoc(AppleEvent event,AppleEvent reply,long refCon)
  141. {
  142.     #pragma unused( reply, refCon )
  143.     
  144.  
  145.     return noErr;
  146.  
  147. }
  148.  
  149.  
  150. //----------------------------------------------------------------------
  151. //
  152. //    GotAEParams - make sure we got proper AE params for an Open 
  153. //                  Document from the Finder
  154. //
  155. //----------------------------------------------------------------------
  156.  
  157. OSErr GotAEParams(AppleEvent *appleEvent)
  158. {
  159.     OSErr            err;
  160.     DescType        type;
  161.     Size            size;
  162.     
  163.     err = AEGetAttributePtr(appleEvent,keyMissedKeywordAttr,
  164.                             typeWildCard,&type,nil,0,&size);
  165.                                             
  166.     if (err == errAEDescNotFound)
  167.         return(noErr);
  168.     
  169.     else
  170.         if (err == noErr)
  171.             return(errAEEventNotHandled);
  172.     
  173.     return err;
  174.  
  175.